﻿@inject IStringLocalizer<DateTimeRangeValidateForm> Localizer

<FormInlineSwitch @bind-Value="@FormRowType" class="mb-3" />

<ValidateForm Model="@Model">
    <div class="@GroupFormClassString">
        <div class="col-12 col-sm-6">
            <DateTimePicker @bind-Value="@Model.DateTime" />
        </div>
        <div class="col-12 col-sm-6">
            <DateTimeRange @bind-Value="@Model.Range" />
        </div>
        <div class="col-12">
            <Button ButtonType="ButtonType.Submit" Icon="fa-fw fa-solid fa-floppy-disk" Text="@Localizer["Submit"]" />
        </div>
    </div>
</ValidateForm>

@code {
    [NotNull]
    private RangeFoo? Model { get; set; }

    private RowType FormRowType { get; set; }

    private string? GroupFormClassString => CssBuilder.Default("row g-3")
        .AddClass("form-inline", FormRowType == RowType.Inline)
        .Build();

    /// <summary>
    /// OnInitialized 方法
    /// </summary>
    protected override void OnInitialized()
    {
        Model = new RangeFoo()
        {
            DateTime = DateTime.Now,
            Range = new DateTimeRangeValue()
            {
                Start = DateTime.Today.AddMonths(-1),
                End = DateTime.Today
            }
        };
    }

    /// <summary>
    /// Foo 类为Demo测试用，如有需要请自行下载源码查阅
    /// Foo class is used for Demo test, please download the source code if necessary
    /// https://gitee.com/LongbowEnterprise/BootstrapBlazor/blob/main/src/BootstrapBlazor.Shared/Data/Foo.cs
    /// </summary>
    private class RangeFoo : Foo
    {
        [Required(ErrorMessage = "{0}不可为空")]
        [Display(Name = "时间范围")]
        public DateTimeRangeValue Range { get; set; } = new();
    }
}
